import java.io.*;

/**
 * Defines a reusable class StreetAddress. One object of class StreetAddress
 * stores the house number (including street), city, state, ZIP, and country for
 * an address.
 * author: MS
 */
public class StreetAddress implements Comparable<StreetAddress>, Serializable{
	private String house;
	private String city;
	private String state;
	private String zip;
	private String country;

	/**
	 * Sets initial values for house, city, state, zip, and country to
	 * "House Number", "City", "State", "Zip Code" and "Country".
	 */
	public StreetAddress() {
		house = "House Number";
		city = "City";
		state = "State";
		zip = "Zip Code";
		country = "Country";
	}

	/**
	 * Sets value for house to house1
	 */
	public void setHouse(String house1) {
		house = house1;
	}

	/**
	 * Sets value for city to city1
	 */
	public void setCity(String city1) {
		city = city1;
	}

	/**
	 * Sets value for state to state1
	 */
	public void setState(String state1) {
		state = state1;
	}

	/**
	 * Sets value for zip to zip1
	 */
	public void setZip(String zip1) {
		zip = zip1;
	}

	/**
	 * Sets value for country to country1
	 */
	public void setCountry(String country1) {
		country = country1;
	}

	/**
	 * return the house
	 * @return String this.house
	 * JZ
	 */
	public String getHouse() {
		return this.house;
	}

	/**
	 * return the city
	 * @return String this.house
	 * JZ
	 */
	public String getCity() {
		return this.city;
	}
	
	/**
	 * return the state
	 * @return String this.ztate
	 * JZ
	 */
	public String getState() {
		return this.state;
	}
	
	/**
	 * return the zip
	 * @return String this.zip
	 * JZ
	 */
	public String getZip() {
		return this.zip;
	}
	
	/**
	 * return the country
	 * @return String this.country
	 * JZ
	 */
	public String getCountry() {
		return this.country;
	}
	
	/**
	 * Returns a string containing house, city, state, zip, and country for a
	 * StreetAddress, formatted according to convention.
	 */
	public String toString() {
		return house + "\n" + city + ", " + state + " " + zip + "\n"
				+ country;
	}
	
	/**
	 * Overrides compareTo method to allow comparison of StreetAddress objects
	 * ***Not used for task 3 but implemented for early testing***
	 * @param s
	 * @return int
	 * JZ
	 */
	@Override public int compareTo(StreetAddress s) {
		final int BEFORE = -1;
		final int EQUAL = 0;
		final int AFTER = 1;
		
		if(this.equals(s)) return EQUAL;
		
		int comparison = this.house.compareTo(s.getHouse());
		if(comparison != 0) return comparison;
		
		comparison = this.city.compareTo(s.getCity());
		if(comparison != 0) return comparison;
		
		comparison = this.state.compareTo(s.getState());
		if(comparison != 0) return comparison;
		
		comparison = this.zip.compareTo(s.getZip());
		if(comparison != 0) return comparison;
		
		comparison = this.country.compareTo(s.getCountry());
		if(comparison != 0) return comparison;
		
		return EQUAL;
	}
	
	/**
	 * Overrides equals method to allow equality comparison of StreetAddress objects
	 * ***Not used for task 3 but implemented for early testing***
	 * @param s
	 * @return boolean
	 * JZ
	 */
	@Override public boolean equals(Object s) {
		if(this == s) return true;
		if(!(s instanceof StreetAddress)) return false;
		
		StreetAddress s2 = (StreetAddress)s;
		
		return(this.city.equals(s2.getCity()) &&
				this.country.equals(s2.getCountry()) &&
				this.state.equals(s2.getState()) &&
				this.zip.equals(s2.getZip()) &&
				this.house.equals(s2.getHouse()));
		
	}
}
